/*  File            server_func.h
 *  --------------------------------------------
 *  Version         2.0
 *  Author          qyorewang@gmail.com
 *  modification    Concurrent model using epoll
 *  --------------------------------------------
 */

#define COMMAND_RECV    1
#define DATA_RECV       2
#define REPLY_SEND      3
#define DATA_SEND       4
#define	BACKLOG		256

typedef struct event_handler
{
    int connect_fd;
    int epoll_fd;
    char *buffer;
    int buffsize;
    int buffpos;
    int state;
    int operation;
    char command[16];
}EH, *EHPTR;

void setnonblock(int fd);
void init_event_handler(EHPTR ehptr, int cfd, int efd);
int slog(FILE* fp, const char *format, ...);
int epoll_add(EHPTR ehptr, uint32_t events);
int epoll_del(EHPTR ehptr);
int init(char* pathname, int init_type, char** image);
int deal_listen(int port);
int deal_accept(int listen_fd);

int com_parse(EHPTR ehptr);
int reply_send(EHPTR ehptr);
int data_recv(EHPTR ehptr);
int data_send(EHPTR ehptr);

